package com.car.action.admin;

import java.math.BigDecimal;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.car.common.model.Message;
import com.car.common.model.Tags;
import com.car.common.model.VipPackage;
import com.car.intercept.AdminInterceptor;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.utils.StringUtil;
import com.utils.SystemClock;

@Before(AdminInterceptor.class)
public class VipPackageController extends Controller {

	public void index() {
		List<VipPackage> list = VipPackage.dao.find("select id,title,days,price,hot,zs_hot,status,CASE status  WHEN '1' THEN '开启' WHEN '2' THEN '禁用'  ELSE '其他' END as status_name from vip_package ");
		setAttr("list", list);
		render("index.html");
	}
	
	public void detail() {
		VipPackage one = VipPackage.dao.findById(getPara("id"));
		setAttr("one", one == null ? new VipPackage() : one);
		render("detail.html");
	}
	
	public void del() {
		Db.delete("delete from vip_package where id = " + getPara("id"));
		renderText("操作成功!");
	}
	
	public void save() {
		VipPackage one = VipPackage.dao.findById(getPara("id"));
		boolean updateFlg = false;
		if (one == null) {
			 one = new VipPackage();
			 one.setCreateTime(SystemClock.now()/1000L);
			 updateFlg = true;
		}
		one.setTitle(getPara("title"));
		one.setType(getParaToInt("type"));
		one.setDays(getPara("days"));
		one.setPrice(new BigDecimal(getPara("price")));
		one.setHot(getParaToInt("hot"));
		one.setZsHot(getParaToInt("zs_hot"));
		one.setStatus(getParaToInt("status"));
		if (updateFlg) {
			one.save();
		} else {
			one.update();
		}
		renderText("操作成功!");
	}
	
	public void high() {
		Db.update("update vip_package set title ='会员 1个月 98.0元送2个月',days = 91 where id = 1");
		Db.update("update vip_package set title ='会员12个月 298.0元(限时特惠)送10000热度',zs_hot = 10000 where id = 3");
		Db.update("update vip_package set title ='至尊永久会员 999.00元 (限时开放)送58800热度',zs_hot = 58800 where id = 11");
		renderText("操作成功!");
	}
	
	public void normal() {
		Db.update("update vip_package set title ='会员 1个月 98.0元',days = 31 where id = 1");
		Db.update("update vip_package set title ='会员12个月 298.0元(限时特惠)',zs_hot = 0 where id = 3");
		Db.update("update vip_package set title ='至尊永久会员 999.00元 (限时开放)',zs_hot = 0 where id = 11");
		renderText("操作成功!");
	}
}
